﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace WindowsFormsApp5.Teachers
{
    public partial class Add : Form
    {
        public Add()
        {
            InitializeComponent();
        }

        private void button2_Click(object sender, EventArgs e)
        {
            this.Close();
        }

        private void Add_Load(object sender, EventArgs e)
        {
            comboBox1.DataSource = WJNDBEntities.dbhelp.Depart.ToList();
            comboBox1.DisplayMember = "Department";
            //for (int i = 0; i < comboBox1.Items.Count; i++)
            //{
            //    string str = comboBox1.GetItemText(comboBox1.Items[i]);
            //    for(int j = i+1; j < comboBox1.Items.Count; j++)
            //    {
            //        String str2 = comboBox1.GetItemText(comboBox1.Items[j]);
            //        if (str2 == str)
            //        {
            //            comboBox1.Items.Remove(comboBox1.Items[j]);
            //        }
            //    }
            //    textBox3.Text = str;
            //}
        }

        private void button1_Click(object sender, EventArgs e)
        {
            string tid = textBox1.Text.Trim();
            string tname = textBox2.Text.Trim();
            string depart = comboBox1.Text.Trim();
           
            Teacher t = new Teacher();
            t.Tid = tid;t.TName = tname;t.Department = depart;
            try
            {
                WJNDBEntities.dbhelp.Teacher.Add(t);
                WJNDBEntities.dbhelp.SaveChanges();
                MessageBox.Show("提交成功！");
                this.Close();
            }
            catch (Exception)
            {
                MessageBox.Show("提交失败！");
            }
        }
    }
}
